package com.xpec.c4.game.datamanager.agent.money;

import java.math.BigDecimal;

import com.ms.player.Player;
import com.ms.service.module.zone.command.BasicDebugCommand;
import com.ms.service.module.zone.command.CommandHelper;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.game.datamanager.BaseDataInfo;
import com.xpec.c4.game.utility.GUIDFactory;
import com.xpec.c4.game.utility.GUIDType;
import com.xpec.c4.game.utility.GameUtility;

/**
 * 假裝贏錢
 * 
 * @author kvn_yang
 */
public class WinMoneyCommand extends BasicDebugCommand {
	/** 贏錢金額 */
	public static final int INDEX_WIN_VALUE = 1;

	private CommandHelper helper = new CommandHelper(getName());

	public WinMoneyCommand() {
	}

	@Override
	public String execute() {
		BasicZoneModule module = getModule();
		if (module == null) {
			return "can't get current module.";
		}

		Player player = getPlayer();
		if (player == null) {
			return "can't get current player.";
		}

		// 贏得金額
		String value = getParam(INDEX_WIN_VALUE);
		if (!GameUtility.isHaveString(value)) {
			return getDescription();
		}

		if (!GameUtility.isNumeric(value)) {
			return getDescription();
		}

		BigDecimal changeValue = new BigDecimal(value);

		// 金錢異動行為
		MoneyChangeWay changeWay = MoneyChangeWay.ADD_SCORE_COMMAND;

		String gameHallId = getZone().getZoneId();
		String gameHallName = "";
		String gameName = "";
		String gameId = "";

		// 金幣
		ChangeCoinLister coinLister = new ChangeCoinLister();
		coinLister.addCoin(CoinType.GOLD, changeValue);

		// 向 dc 要求變更
		// callback BasicZone.onAddMoneyCommandToDcCallback()
		module.getPlayerDataAgent().updatePlayerMoneyToDC(GUIDFactory.createUUID(GUIDType.TYPE_COMMAND_ORDER_ID),
				player, coinLister, changeWay, MoneyChangeParam.NO_JACKPOT, false, null, null, module, gameId,
				gameName, gameHallId, gameHallName, null, this, "onWinMoneyCommandToDcCallback");

		return "ok";
	}

	@Override
	public String getDescription() {
		return getName() + " [win value]";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ms.service.module.zone.command.BasicDebugCommand#getShortDescription
	 * ()
	 */
	@Override
	public String getShortDescription() {
		return "simulate player win money.";
	}

	@Override
	public String getName() {
		return "winmoney";
	}

	/**
	 * 更新錢到 dc 回來的 callback
	 * 
	 * @param obj
	 * @param userObject
	 * @see WinMoneyCommand
	 */
	public void onWinMoneyCommandToDcCallback(BaseDataInfo obj, Object... userObject) {
		MoneyChangeParam param = (MoneyChangeParam) obj.getData();
		Player player = getPlayer();
		if (player == null) {
			return;
		}

		sendDebugCommandResponse(player.getSessionID(), param.getResultString());
	}
}
